/**
 * Module dependencies.
 */

const express = require('express');
const site = require('../controllers/site');
const user = require('../controllers/user');
const sign = require('../controllers/sign');
const topic = require('../controllers/topic');
const auth = require('../middlewares/auth');
const reply = require('../controllers/reply');
const config = require('../config');
const limit = require('../middlewares/limit');

const router = express.Router();

/* GET home page. */
// router.get('/', site.index);

//user controller
router.get('/user', user.getUser);//个人用户主页
router.get('/getUserById', user.getUserById);
router.get('/getUserByName', user.getUserByName);
router.get('/user/collections', user.listCollectedTopics);  // 用户收藏的所有话题页
router.get('/user/listReplies', user.listReplies);  // 用户参与的所有回复页
router.post('/user/updateInfo', auth.userRequired, user.updateInfo); //设置更新用户信息
router.post('/user/uploadAvatar', auth.userRequired, user.uploadAvatar); //设置更新用户信息

//sign controller
// router.get('/signup', sign.showSignup);//跳转到注册页面
router.post('/signup', sign.signup); //提交注册信息
router.post('/signin', sign.login);  // 登录校验
router.get('/active_account', sign.activeAccount);  //帐号激活
router.post('/signout', sign.signout); //退出

//topic
// 新建文章界面或重新编辑
router.post('/topic/create', auth.userRequired, limit.peruserperday('create_topic', config.create_post_per_day, {showJson: false}), topic.put);
router.post('/topic/delete', auth.userRequired, topic.delete); //删除某话题
router.post('/topic/collect', auth.userRequired, topic.collect);//收藏某话题
router.post('/topic/removeCollect', auth.userRequired, topic.removeCollect);//取消收藏


//获取所有文章列表
// router.get('/topic')
router.get('/topic', topic.getFullTopicsBySkit);  // 获取所有话题
router.get('/topicType', topic.topicType); //话题类型
router.get('/topicDetail', topic.getTopicById);// 查看详情
router.get('/topicByUser', topic.getTopicsByUser);//每个用户所发布的文章列表
router.get('/topicTop', topic.getTopicsTop);

//reply controller
router.post('/reply', auth.userRequired, limit.peruserperday('create_reply', config.create_reply_per_day, {showJson: false}), reply.add); // 提交一级回复
router.post('/reply/delete', auth.userRequired, reply.delete); //删除回复
router.post('/reply/update', auth.userRequired, reply.update); //重新编辑回复

router.post('/upload', auth.userRequired, topic.upload); //上传图片s

module.exports = router;
